# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Xin Sun <sun.simpson@gmail.com>

_realname=szip
pkgbase="mingw-w64-${_realname}"
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.1.1
pkgrel=2
pkgdesc="Extended-Rice lossless compression algorithm implementation (mingw-w64)"
arch=('any')
license=("custom")
url="https://www.hdfgroup.org/doc_resource/SZIP/"
source=("https://www.hdfgroup.org/ftp/lib-external/szip/${pkgver}/src/szip-${pkgver}.tar.gz"
        "szip-default-import-suffix.patch"
        "szip-fix-install-docs.patch"
        "szip-proper-library-names-mingw.patch")
sha256sums=('21ee958b4f2d4be2c9cabfa5e1a94877043609ce86fde5f286f105f7ff84d412'
            '82177807ccbf0fb8c76eefacd42b3e43969172cac92f3eeb512a7e356c46dc1a'
            '6f6b306c170ae6e6405f8bb5fbce5c9eaa7e100ec5392a687a9b313a2df0813a'
            'd263b140bf76f50a9dfec198e284b897881d0412abf7b93542a0595adfc99375')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-cmake")
options=('staticlibs' 'strip')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/szip-default-import-suffix.patch
  patch -p1 -i ${srcdir}/szip-fix-install-docs.patch
  patch -p1 -i ${srcdir}/szip-proper-library-names-mingw.patch
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DBUILD_SHARED_LIBS=ON \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_SKIP_RPATH=ON \
  ../${_realname}-${pkgver}
  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR=${pkgdir} install

  install -Dm644 ${srcdir}/${_realname}-${pkgver}/COPYING ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING
}
